﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace VocabManager.DataLayer
{
    
    public class DatabaseManager
    {
        private static string _ConnectionString = @"isostore:/FlashCardDatabase.sdf";
        private DatabaseManager()
        {
            _context = new FlashCardContext(_ConnectionString);
            CreateDatabase();
        }
       static DatabaseManager _instance;
       public static DatabaseManager Insatance
        {
            get
            {
                if (_instance == null)
                    _instance = new DatabaseManager();
                return _instance;
            }
        }
        private FlashCardContext _context;
        public FlashCardContext DataContext
        {
            get 
            {
                return _context;
            }
        }
        private bool CreateDatabase()
        {
            try
            {
                if (!_context.DatabaseExists())
                _context.CreateDatabase();
                return true;
            }
            catch (Exception ex)
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    MessageBox.Show(ex.Message);
                }
                return false;
            }
        }
    }
}
